package com.cndw.kungfu.model.pvp.api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.cndw.kungfu.ext.LogUtil;
import com.cndw.kungfu.model.pvp.campcross.CampCrossReport;
import com.cndw.kungfu.model.pvp.campcross.CampCrossReportBattle;
import com.cndw.kungfu.model.pvp.campcross.CampTeam;
import com.cndw.kungfu.model.pvp.war.WarFighter;
import com.cndw.rpg.framework.ResponseMessage;

public class CampApiClient {

	public static Object join(CampTeam campTeam) {
		return ApiClient.setdApi(ApiCore.crossSid(), ApiConfig.campJoin, ApiCore.currentSid(), campTeam);
	}

	public static ResponseMessage show(long uid) {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campShow, 0, ApiCore.currentSid(), uid);
	}

	public static ResponseMessage order() {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campOrder, 0, ApiCore.currentSid());
	}

	@SuppressWarnings("unchecked")
	public static Collection<WarFighter> getFighters(int sid, String ids) {
		Object message = ApiClient.setdApi(sid, ApiConfig.warFighters, ids);

		if (message == null) {
			LogUtil.getMain().debug("err warFighters null " + sid);
			return null;
		}
		if (message.getClass().isArray()) {
			List<WarFighter> allPlayers = new ArrayList<WarFighter>();
			Object[] pArray = (Object[]) message;
			for (Object warPlayer : pArray) {
				allPlayers.add((WarFighter) warPlayer);
			}
			return allPlayers;
		} else {
			return (Collection<WarFighter>) message;
		}

	}

	public static ResponseMessage first(long uid) {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campFirst, 0, ApiCore.currentSid(), uid);
	}

	public static ResponseMessage team(long masterId) {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campTeam, 0, ApiCore.currentSid(), masterId);
	}

	public static ResponseMessage teamlist() {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campTeamList, 0, ApiCore.currentSid());
	}

	public static ResponseMessage log(long uid) {
		return ApiClient.apiMessage(ApiCore.crossSid(), ApiConfig.campLog, 0, ApiCore.currentSid(), uid);
	}

	public static void sendRecords(int area, CampCrossReport campCrossReport) {
		ApiClient.areaMessage(area, ApiConfig.campRecordsNotify, campCrossReport);
	}

	public static void sendBattle(int sid, CampCrossReportBattle reportBattle) {
		if (sid <= 0 ) {//npc 过滤
			return ;
		}
		ApiClient.apiMessage(sid, ApiConfig.campBattle, 1000, reportBattle);
	}

	public static void sendAward(int sid, String ids, int orderId) {
		ApiClient.apiMessage(sid, ApiConfig.campAward, 1000, ids, orderId);
	}

	public static void state(int area, boolean open) {
		ApiClient.areaMessage(area, ApiConfig.campState, open);
	}



}
